<template>
  <div class='aui-card--fill scroll-box card-box'>
    <div class='pane-shell'>
      <el-form :model="dataForm"
               v-loading="dataListLoading"
               :element-loading-text="$t('loading')"
               ref="dataForm"
               label-position="top"
               label-width="200px">
        <el-form-item prop="value"
                      label="默认主页配置"
                      styel="margin-top: 30px"
                      :rules="required()">
          <el-input v-model.trim="dataForm.value"
                    maxlength="100"
                    placeholder="请输入路由"></el-input>
        </el-form-item>
        <div style="height: 50px;">
          <el-button style="float: right;"
                     @click="save()">{{ $t("save") }}</el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import minFormValidate from '@/mixins/form-validate'
import debounce from 'lodash/debounce'
export default {
  mixins: [mixinViewModule, minFormValidate],
  name: '',
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '', // 数据列表接口，API地址
        getDataListIsPage: true, // 数据列表接口，是否需要分页？
        addOrUpdateURL: '', // 添加或修改接口，API地址
        getDataInfoURL: '', // 数据详情，API地址
        updateStatusURL: '',
        deleteURL: '', // 删除接口，API地址
        deleteIsBatch: true, // 删除接口，是否需要批量？
        exportURL: '' // 导出接口，API地址
      },
      dataForm: {
        type: 3,
        value: ''
      }
    }
  },
  mounted () {
    this.getIndexUrl()
  },
  methods: {
    // 获取当前默认主页
    getIndexUrl () {
      this.$http.get('system/sysGlobalConfig/getSysGlobalConfig?type=3').then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm.value = res.data.value
      })
    },
    // 表单提交
    save: debounce(
      function () {
        this.$refs.dataForm.validate((valid) => {
          if (valid) {
            this.$http.put('system/sysGlobalConfig/', this.dataForm).then(({ data: res }) => {
              if (res.code !== 0) {
                return this.$message.error(res.msg)
              }
              this.$message.success('保存成功')
            })
          }
        })
      },
      1000,
      { leading: true, trailing: false }
    )
  }
}
</script>
<style lang="scss" scoped>
</style>
